using B.S.NewMedical.Api.Write.Application.Command.Doctor;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.NewMedical.Api.Write.Controllers
{
    /// <summary>
    /// 医生工作站控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class DoctorWorkstationController : ControllerBase
    {
        private readonly IMediator _mediator;

        public DoctorWorkstationController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取医生待就诊患者列表
        /// </summary>
        /// <param name="doctorId">医生ID</param>
        /// <param name="visitDate">就诊日期（可选）</param>
        /// <returns></returns>
        [HttpGet("waiting-patients")]
        public async Task<IActionResult> GetWaitingPatients(int doctorId, DateTime? visitDate = null)
        {
            var command = new GetWaitingPatientsCommand
            {
                DoctorId = doctorId,
                VisitDate = visitDate
            };

            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 开始接诊
        /// </summary>
        /// <param name="command">接诊命令</param>
        /// <returns></returns>
        [HttpPost("start-visit")]
        public async Task<IActionResult> StartVisit([FromBody] StartVisitCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 开处方
        /// </summary>
        /// <param name="command">开处方命令</param>
        /// <returns></returns>
        [HttpPost("add-prescription")]
        public async Task<IActionResult> AddPrescription([FromBody] AddPrescriptionCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 开检验单
        /// </summary>
        /// <param name="command">开检验单命令</param>
        /// <returns></returns>
        [HttpPost("add-laborder")]
        public async Task<IActionResult> AddLaborder([FromBody] AddLaborderCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 获取待收费项目
        /// </summary>
        /// <param name="cardNo">就诊卡号</param>
        /// <returns></returns>
        [HttpGet("pending-charge-items")]
        public async Task<IActionResult> GetPendingChargeItems(string cardNo)
        {
            var command = new GetPendingChargeItemsCommand
            {
                CardNo = cardNo
            };

            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 收费
        /// </summary>
        /// <param name="command">收费命令</param>
        /// <returns></returns>
        [HttpPost("process-charge")]
        public async Task<IActionResult> ProcessCharge([FromBody] ProcessChargeCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 医疗卡充值
        /// </summary>
        /// <param name="command">充值命令</param>
        /// <returns></returns>
        [HttpPost("recharge-card")]
        public async Task<IActionResult> RechargeCard([FromBody] RechargeCardCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }
    }
} 